<!-- 销售订单表编辑弹窗 -->
<template>
  <el-dialog
    :title="isUpdate?'修改销售订单表':'添加销售订单表'"
    :visible="visible"
    width="460px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="82px">
        <el-form-item
          label="单据编号:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.danjNo"
            placeholder="请输入单据编号"
            clearable/>
        </el-form-item>
        <el-form-item
          label="单位编号:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.danwNo"
            placeholder="请输入单位编号"
            clearable/>
        </el-form-item>
        <el-form-item
          label="业务员:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.yewStaff"
            placeholder="请输入业务员"
            clearable/>
        </el-form-item>
        <el-form-item
          label="二级单位编号:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.erjiDanwNo"
            placeholder="请输入二级单位编号"
            clearable/>
        </el-form-item>
        <el-form-item
          label="开票时间:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.kaipTime"
            placeholder="请输入开票时间"
            clearable/>
        </el-form-item>
        <el-form-item
          label="客户备注:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.kehNotes"
            placeholder="请输入客户备注"
            clearable/>
        </el-form-item>
        <el-form-item label="行号:" prop="hanghao">
          <el-input-number
            :min="0"
            v-model="form.hanghao"
            placeholder="请输入行号"
            controls-position="right"
            class="ele-fluid ele-text-left"/>
        </el-form-item>
        <el-form-item
          label="商品编号:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.shangpNo"
            placeholder="请输入商品编号"
            clearable/>
        </el-form-item>
        <el-form-item
          label="批号要求:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.lotRequest"
            placeholder="请输入批号要求"
            clearable/>
        </el-form-item>
        <el-form-item
          label="下传状态:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.zt"
            placeholder="请输入下传状态"
            clearable/>
        </el-form-item>
        <el-form-item
          label="提货方式:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.tihWay"
            placeholder="请输入提货方式"
            clearable/>
        </el-form-item>
        <el-form-item
          label="金税票号:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.fapNo"
            placeholder="请输入金税票号"
            clearable/>
        </el-form-item>
        <el-form-item
          label="NC组织编码:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.khZzbm"
            placeholder="请输入NC组织编码"
            clearable/>
        </el-form-item>
        <el-form-item
          label="九州通业主编码:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.yezId"
            placeholder="请输入九州通业主编码"
            clearable/>
        </el-form-item>
        <el-form-item
          label="编码:"
          prop="name">
          <el-input
            :maxlength="20"
            v-model="form.dizId"
            placeholder="请输入编码"
            clearable/>
        </el-form-item>
    </el-form>
    <div slot="footer">
      <el-button @click="updateVisible(false)">取消</el-button>
      <el-button
        type="primary"
        @click="save"
        :loading="loading">保存
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'C37InfCkKpdBillEdit',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      // 表单数据
      form: Object.assign({}, this.data),
      // 表单验证规则
      rules: {
        danjNo: [
          {required: true, message: '请输入单据编号', trigger: 'blur'}
        ],
        danwNo: [
          {required: true, message: '请输入单位编号', trigger: 'blur'}
        ],
        yewStaff: [
          {required: true, message: '请输入业务员', trigger: 'blur'}
        ],
        erjiDanwNo: [
          {required: true, message: '请输入二级单位编号', trigger: 'blur'}
        ],
        kaipTime: [
          {required: true, message: '请输入开票时间', trigger: 'blur'}
        ],
        kehNotes: [
          {required: true, message: '请输入客户备注', trigger: 'blur'}
        ],
        hanghao: [
          {required: true, message: '请输入行号', trigger: 'blur'}
        ],
        shangpNo: [
          {required: true, message: '请输入商品编号', trigger: 'blur'}
        ],
        num: [
          {required: true, message: '请输入数量', trigger: 'blur'}
        ],
        price: [
          {required: true, message: '请输入价格', trigger: 'blur'}
        ],
        lotRequest: [
          {required: true, message: '请输入批号要求', trigger: 'blur'}
        ],
        zt: [
          {required: true, message: '请输入下传状态', trigger: 'blur'}
        ],
        tihWay: [
          {required: true, message: '请输入提货方式', trigger: 'blur'}
        ],
        fapNo: [
          {required: true, message: '请输入金税票号', trigger: 'blur'}
        ],
        khZzbm: [
          {required: true, message: '请输入NC组织编码', trigger: 'blur'}
        ],
        yezId: [
          {required: true, message: '请输入九州通业主编码', trigger: 'blur'}
        ],
        dizId: [
          {required: true, message: '请输入编码', trigger: 'blur'}
        ],
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
    };
  },
  watch: {
    data() {
      if (this.data) {
        this.form = Object.assign({}, this.data);
        this.isUpdate = true;
      } else {
        this.form = {};
        this.isUpdate = false;
      }
    }
  },
  methods: {
    /* 保存编辑 */
    save() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true;
          this.$http[this.isUpdate ? 'put' : 'post'](this.isUpdate ? '/c37infckkpdbill/edit' : '/c37infckkpdbill/add', this.form).then(res => {
            this.loading = false;
            if (res.data.code === 0) {
              this.$message.success(res.data.msg);
              if (!this.isUpdate) {
                this.form = {};
              }
              this.updateVisible(false);
              this.$emit('done');
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            this.loading = false;
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  }
}
</script>

<style scoped>
</style>
